package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.constant.HttpResultEnum;
import com.dongdongshop.data.DataResult;
import com.dongdongshop.pojo.seller.TbSeller;
import com.dongdongshop.service.seller.SellerService;
import com.dongdongshop.util.ShiroUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 商家后台管理
 * @Author Eayon
 * @Date 2020/2/27 10:14
 */
@Controller
@RequestMapping("seller")
public class SellerController {

    private Logger log = LoggerFactory.getLogger(SellerController.class);

    @Reference
    private SellerService sellerService;

    /**
     * 商家注册
     * @param seller
     * @return
     */
    @RequestMapping(value = "registerSeller",method = RequestMethod.POST)
    @ResponseBody
    public DataResult registerSeller(TbSeller seller){
        try {
            //给密码加密  这里我们用用户的id值作为盐
            String password = ShiroUtils.encryptPassword("MD5", seller.getPassword(), seller.getSellerId(), 1);
            seller.setPassword(password);
            sellerService.registerSeller(seller);
        }catch (Exception e){
            log.error("商家注册异常",e);
            return new DataResult(HttpResultEnum.ERROR.getCode(),HttpResultEnum.ERROR.getMessage());
        }
        return new DataResult(HttpResultEnum.SUCCESS.getCode(),HttpResultEnum.SUCCESS.getMessage());
    }

}
